/**
 * Created by hcadmin on 16/3/3.
 */

define([
    "jquery",
    "IO",
    "UPLOADUI",
    "UPLOAD",
    "jqueryUI",
    "bootbox",
    //"text!/js/biz/keb/activity/definebt.html"
], function ($, IO, upui, up, jui, bootbox, definebt) {

    $('#fileupload').fileupload({
        url: '/upload',
        dataType: 'json',
        autoUpload: true,
        acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
        maxFileSize: 10000000, // 10 MB
        disableImageResize: /Android(?!.*Chrome)|Opera/
            .test(window.navigator.userAgent),
        previewMaxWidth: 150,
        previewMaxHeight: 150,
        previewCrop: true
    }).on('fileuploadadd', function (e, data) {
        document.getElementById('upimgs').src = '/images/loading.gif';

    }).on('fileuploadprocessalways', function (e, data) {
        //console.log("fileuploadprocessalways",data);
    }).on('fileuploadprogressall', function (e, data) {
        //console.log("fileuploadprogressall",data);
    }).on('fileuploaddone', function (e, data) {
        //alert('Img'+youpaiImg);
        //alert(data._response.result.url);
        //document.getElementById('upimgs').src = data._response.result.url;
        //console.log(youpaiImg);
        //  console.log("fileuploaddone",data);
        var alt = $(e.target).attr('alt');
        if (!alt)
            alt = '';
        console.log("#upimgs" + alt);
        $("#upimgs" + alt).attr("src", data._response.result.url);
    });
    $(document).on("click",".publish",function(){
        var vocabulary_id=$(this).data("id");
        var content = $("#vocabulary_name").val();
        var fullChar = $("#vocabulary_fullChar").val();
        var image = $("#upimgs").attr("src");
        var description = editor.html();
        var context = editor2.html();
        var param = {vocabulary_id:vocabulary_id,fullChar:fullChar,content:content,image:image,description:description,context:context};

        if(content==""){
            alert("请输入词条名称");
            return;
        }
        if(fullChar==""){
            alert("请输入词条全拼");
            return;
        }

        if(description==""){
            alert("请输入词条含义");
            return;
        }

        if(image=="/images/addimg.png"){
            alert("请上传词条照片");
            return;
        }

        if(context==""){
            alert("请输入应用语境");
            return;
        }

        if(param&&param!='undefined'){
            bootbox.confirm("确定要修改该词条",function(result){
                if(result) {
                    IO.post("api/citiao_update",param,function(d){
                        bootbox.alert(d.msg,function(){
                            if (d.code == 0) {
                                location.href = '/pte/citiao_lb';
                            }
                        })
                    });
                }
            });
        }
    })
});